package cn.chenhao.basic.controller;

import cn.chenhao.basic.exception.BusinessException;
import cn.chenhao.basic.util.AjaxResult;
import cn.chenhao.user.service.IVerifyCodeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
@Api(tags = "短信验证码接口",description = "短信验证码接口接口详细描述")
@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;
    //一定情况下Map能够代替类使用

    @PostMapping("/smsCode")
    public AjaxResult sendCode(@RequestBody Map<String,String> params){
        try {
            //register:用户注册  binder:用户绑定
            verifyCodeService.sendSmsCode(params);
            return AjaxResult.me();
        }
        catch (BusinessException exception) {
            exception.printStackTrace();
            return AjaxResult.me().setMessage("发送失败，请稍后再试！");
        }
        catch (Exception exception) {
            exception.printStackTrace();
            return AjaxResult.me().setMessage("系统错误，请等哈再试！");
        }
    }

}
